package com.mallcloud.mall.mall.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mallcloud.mall.common.core.constant.enums.mall.PointsProductEnum;
import com.mallcloud.mall.mall.api.entity.MallPointsProductModel;
import com.mallcloud.mall.mall.mapper.MallPointsProductMapper;
import com.mallcloud.mall.mall.service.MallPointsProductService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 积分商品
 */
@Service
public class MallPointsProductServiceImpl extends ServiceImpl<MallPointsProductMapper, MallPointsProductModel> implements MallPointsProductService {

	@Override
	public Boolean savePointsProduct(MallPointsProductModel model) {
		model.setStatus(PointsProductEnum.ProductStatusEnum.Y.name());
		model.setReleaseTime(new Date());
		return this.save(model);
	}

	@Override
	public Boolean removePointsProduct(String id) {
		MallPointsProductModel model = new MallPointsProductModel();
		model.setId(id);
		model.setStatus(PointsProductEnum.ProductStatusEnum.D.name());
		model.setDeleteDateTime(new Date());
		return this.updateById(model);
	}

	@Override
	public Boolean removePointsProducts(List<String> ids) {
		if(ids.isEmpty()){
			return Boolean.TRUE;
		}
		return this.update(new LambdaUpdateWrapper<MallPointsProductModel>()
				.in(MallPointsProductModel::getId, ids)
				.set(MallPointsProductModel::getStatus, PointsProductEnum.ProductStatusEnum.D.name())
				.set(MallPointsProductModel::getDeleteDateTime, new Date())
		);
	}

}
